package com.xt.core.data;

import javax.persistence.Column;
import javax.persistence.Entity;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.InheritanceType;
import javax.persistence.Inheritance;
import javax.persistence.SequenceGenerator;
import javax.persistence.Transient;
import javax.persistence.MappedSuperclass;


import org.hibernate.annotations.GenericGenerator;

/**
 * This class represents the base db object in application
 * 
 * @author Author:  txiao
 * @version Revision: 1.0, Date: 21.09.2009
 * 
 */
@MappedSuperclass
//@Entity
//@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class BasicDBObject extends BasicObject {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 7623654946405150594L;
	
	//@Id //if id's annotaion is in field, the other properties' annotion are also in field
	//@Column(name="id", nullable = false, unique = true)
	//@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="SpendenSeq")
	//@SequenceGenerator(name="SpendenSeq",sequenceName="HIBERNATE_SEQUENCE",allocationSize=1, initialValue=1)
	//@GeneratedValue(strategy = GenerationType.AUTO) //does't work under oracle
	@Id @GeneratedValue
	@Column(name="id", nullable = false)
	//if defined generator here, take the maximal id in all tables
	//if defined in class self, take only the maximal id from the table where the object is.!
	//@GenericGenerator(name = "incrementGenerator", strategy = "increment")     
	//@GenericGenerator(name = "incrementGenerator", strategy = "identity") //using hibernate_sequence
	//@GenericGenerator(name = "incrementGenerator", strategy = "assigned")  //does't work under oracle
	protected Long id;
		
	/************* getter and setter ********************/
	public Long getId() {
		return id;
	}
	
	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}
	
	/***************** basic functions *****************/
	public String toString() {

		return "BaseDBObject{" + "id=" + id + " }";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 0;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (getClass() != obj.getClass()){
			return false;
		}
		BasicDBObject other = (BasicDBObject) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (other.id == null)
			return false;
		else if(id.longValue() == other.id.longValue())
			return true;
		return true;
	}
	

	
	/*
     * Add your function here
     */
	
}
